package com.m3839.sdk.pay.bean;

import com.m3839.sdk.common.base.BaseBean;
import com.m3839.sdk.common.core.Constant;
import com.m3839.sdk.pay.constant.PayConstant;

import org.json.JSONObject;

/**
 * Description:HykbOrderInfo
 *
 * @author 陈宝阳
 * @create 2020/8/12 18:20
 */
public class OrderInfo extends BaseBean<OrderInfo> {
  /**
   * "orderId": "2020081217074877933007",
   *         "payType": "alipay",
   *         "payParams": {
   *             "params": "alipay_sdk=alipay-sdk-php-20180705&app_id=2019022763388334&biz_content=%7B%22body%22%3A%22%5Cu5546%5Cu54c1%5Cu540d%22%2C%22subject%22%3A%22%5Cu5546%5Cu54c1%5Cu540d%22%2C%22out_trade_no%22%3A%222020081217074877933007%22%2C%22timeout_express%22%3A%2290m%22%2C%22total_amount%22%3A10%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay&notify_url=https%3A%2F%2Fpay.3839.com%2Fzfb%2Fnotify&sign_type=RSA2&timestamp=2020-08-12+17%3A07%3A48&version=1.0&sign=2r79XEthe09vOdY3KByC2UWkRYBgb4NIEs3lBlaZoPHcc3RKhzFPSt%2F3GG9MQL4zek6NBIJ6nYOETbYrzr5g2TYr10jT3IYc4%2FYWSv1A%2BloVxV0lWZB0Vdi8gKSmxyiHXCapBLzd4vq2dJBGwmrCXV4fQpldhL8SsN8tMRCgsMPkR8qoI5B3Rsr2bu4xGFbKFK5nOwcqumGv7DrwJsALT3Z0WD%2F%2BKTdRsuc%2BNUgF4VfJr7J%2BuayuR%2F6oVJp0bUi5tMFFjFNdVPKqC%2BQEgfy0BvgORkaih6JOABeIN%2FKBDUFMBnCK1TewTBHjfCUIewHl8eNZQ%2FPzbQoHAjJ0ZJDt3g%3D%3D"
   *         }
   */

  /** 支付订单号 */
  public String orderId;
  /** 支付方式 */
  public String payType;
  /** 支付参数 */
  public PayParams payParams;

  @Override
  public OrderInfo parseBean(JSONObject jsonObject) {
    if(jsonObject == null) {
      return null;
    }

    orderId = jsonObject.optString(Constant.HYKB_KEY_RESPONSE_PAY_ORDER);
    payType = jsonObject.optString(Constant.HYKB_KEY_RESPONSE_PAY_TYPE);
    JSONObject paramJson = jsonObject.optJSONObject(Constant.HYKB_KEY_RESPONSE_PAY_PARAMS);
    payParams = new PayParams();
    if(paramJson != null) {
      if (PayConstant.HYKB_VALUE_PAY_CHANNEL_WECHAT_H5.equals(payType)) {
        payParams.url = paramJson.optString(Constant.HYKB_KEY_RESPONSE_URL);
      } else if (PayConstant.HYKB_VALUE_PAY_CHANNEL_ALIPAY.equals(payType)) {
        payParams.params = paramJson.optString(Constant.HYKB_KEY_RESPONSE_PARAM);
      }
    }
    return this;
  }

  public static final class PayParams  {
    /** 支付宝的参数配置 */
    public String params;
    /** 微信H5的地址 */
    public String url;
  }

}
